package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.G_Collection;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CollectionMapper;

import com.ruoyi.system.service.ICollectionService;
import com.ruoyi.common.core.text.Convert;

/**
 * 收藏Service业务层处理
 * 
 * @author 张颖
 * @date 2025-01-08
 */
@Service
public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, G_Collection> implements ICollectionService

{
    @Autowired
    private CollectionMapper collectionMapper;

    /**
     * 查询收藏
     * 
     * @param collectionId 收藏主键
     * @return 收藏
     */
    @Override
    public G_Collection selectCollectionByCollectionId(Long collectionId)
    {
        return collectionMapper.selectCollectionByCollectionId(collectionId);
    }

    /**
     * 查询收藏列表
     * 
     * @param collection 收藏
     * @return 收藏
     */
    @Override
    public List<G_Collection> selectCollectionList(G_Collection collection)
    {
        return collectionMapper.selectCollectionList(collection);
    }

    /**
     * 新增收藏
     * 
     * @param collection 收藏
     * @return 结果
     */
    @Override
    public int insertCollection(G_Collection collection)
    {
        collection.setCreateTime(DateUtils.getNowDate());
        return collectionMapper.insertCollection(collection);
    }

    /**
     * 修改收藏
     * 
     * @param collection 收藏
     * @return 结果
     */
    @Override
    public int updateCollection(G_Collection collection)
    {
        collection.setUpdateTime(DateUtils.getNowDate());
        return collectionMapper.updateCollection(collection);
    }

    /**
     * 批量删除收藏
     * 
     * @param collectionIds 需要删除的收藏主键
     * @return 结果
     */
    @Override
    public int deleteCollectionByCollectionIds(String collectionIds)
    {
        return collectionMapper.deleteCollectionByCollectionIds(Convert.toStrArray(collectionIds));
    }

    /**
     * 批量软删除收藏
     *
     * @param collectionIds 需要软删除的收藏主键
     * @return 结果
     */
    @Override
    public int softDeleteCollectionByCollectionIds(String collectionIds)
    {
        String[] strArray = Convert.toStrArray(collectionIds);
        int count = 0;
        for (String s : strArray) {
            G_Collection collection = collectionMapper.selectCollectionByCollectionId(Long.valueOf(s));
            collection.setIsDelete(1);
            int i = collectionMapper.updateCollection(collection);
            count = count + i;
        }
        return count;
    }

    /**
     * 删除收藏信息
     * 
     * @param collectionId 收藏主键
     * @return 结果
     */
    @Override
    public int deleteCollectionByCollectionId(Long collectionId)
    {
        return collectionMapper.deleteCollectionByCollectionId(collectionId);
    }
}
